﻿using log4net;
using System;
using System.Web.Mvc;

namespace CIS.Web.Filters
{
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
	public class CISHandleErrorAttribute : HandleErrorAttribute
	{
		public override void OnException(ExceptionContext filterContext)
		{
			string controllerName = filterContext.RouteData.Values["controller"].ToString();
			string actionName = filterContext.RouteData.Values["action"].ToString();
			ILog logger = LogManager.GetLogger(controllerName);
			logger.Error(string.Format(
					"Action : {0} ; User : {1}",
					actionName,
					filterContext.HttpContext.User.Identity.Name),
				filterContext.Exception);

			base.OnException(filterContext);
		}
	}
}